package 扑克牌;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardList {
    private List<Card>list=new ArrayList<>();
    private String[] suits=new String[]{"♠", "♥", "♣", "♦"};
    //买牌
    public CardList(){
        for (int i = 1; i <=13; i++) {
            for (int j = 0; j < 4; j++) {
                this.list.add(new Card(suits[j],i));
            }
        }
    }
    public List<Card> getList() {
        return list;
    }
    //交换
    private void swap(int index,int tmp){
        Card card=list.get(tmp);//存
        list.set(tmp,list.get(index));//放
        list.set(index,card);//放
    }
    //洗牌
    public void shuffle(){
        Random random=new Random();
        for (int i = list.size()-1; i >0; i--) {
            int index=random.nextInt(i);//随机下标
            swap(index,i);//当前下标
        }

    }
    //发牌
    public List<List<Card>> licenSing(){
        List<Card>play1=new ArrayList<>();
        List<Card>play2=new ArrayList<>();
        List<Card>play3=new ArrayList<>();
        List<List<Card>> arr=new ArrayList<>();
        arr.add(play1);
        arr.add(play2);
        arr.add(play3);
        for (int i = 0; i < 5;i++) {//每个人5张牌
            for (int j = 0; j <arr.size() ; j++) {//3个人 每人一张
                arr.get(j).add(list.remove(0));
            }
        }
        return arr;
    }
}
